<?php
include_once('libs/class.database.php');

class Biodata
{
	public $link;
	
	function __construct()
	{
		$konek = new Database();
		$this->link=$konek->connect();
	}
	
	function createBiodata($nama, $alamat, $telp, $fax, $email, $id_jns_anggota, $id_username)
	{
		$date_created=date('Y-m-d');
		$query=$this->link->prepare("INSERT INTO biodata(nama, alamat, telp, fax, email, id_jns_anggota, id_username, date_created)
			VALUES(?,?,?,?,?,?,?,?)");
		$data=array($nama, $alamat, $telp, $fax, $email, $id_jns_anggota, $id_username, $date_created);
		$query->execute($data);
		$jml_row=$query->rowCount();
		return $jml_row;
	}
	
	function getBiodata($id_username)
	{
		$query=$this->link->query("SELECT b.id id, b.nama nama, b.alamat alamat, b.telp telp, b.fax fax, b.email email, b.id_jns_anggota id_jns_anggota, b.id_username id_username, j.id id_jns, j.nama nama_jns FROM biodata b LEFT JOIN jns_anggota j on b.id_jns_anggota=j.id WHERE b.id_username='$id_username'");
		$jml_data=$query->rowCount();
		if($jml_data==1)
		{
			$hasil=$query->fetchAll();
			return $hasil;
		}
		else
		{
			return $jml_data;
		}
	}
	
	function getNamaBiodata($id_username)
	{
		$query=$this->link->query("SELECT b.id id, b.nama nama, b.alamat alamat, b.telp telp, b.fax fax, b.email email, b.id_jns_anggota id_jns_anggota, b.id_username id_username, j.id id_jns, j.nama nama_jns FROM biodata b LEFT JOIN jns_anggota j on b.id_jns_anggota=j.id WHERE b.id_username='$id_username'");
		$jml_data=$query->rowCount();
		if($jml_data==1)
		{
			$hasil=$query->fetchAll();
			foreach($hasil as $row)
			{
				$nama=$row['nama'];
			}
			return $nama;
		}
		else
		{
			return $jml_data;
		}
	}
	
	function updateBiodata($id, $nama, $alamat, $telp, $fax, $email, $id_jns_anggota)
	{
		$query=$this->link->query("UPDATE biodata SET nama='$nama', alamat='$alamat', telp='$telp', fax='$fax', email='$email', id_jns_anggota='$id_jns_anggota' WHERE id='$id'");
		$hasil=$query->rowCount();
		return $hasil;
	}
}

?>